package com.axc.brilliant.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axc.brilliant.domain.WechatBillDO;
import com.axc.brilliant.service.WechatBillService;
import com.axc.common.annotation.Log;
import com.axc.common.utils.PageLayUi;
import com.axc.base.controller.BaseController;
import com.axc.common.utils.PageUtils;
import com.axc.common.utils.Query;
import com.axc.common.utils.R;

/**
 * 流水表
 * 
 * @author admin
 * @email yfq900108@163.COM
 * @date 2019-08-12 22:42:42
 */
 
@Controller
@RequestMapping("/brilliant/wechatBill")
public class WechatBillController extends BaseController {

	//添加日志模块
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private WechatBillService wechatBillService;

	//region 视图
	@GetMapping()
	@RequiresPermissions("brilliant:wechatBill:wechatBill")
	String WechatBill(){
	    return "brilliant/wechatBill/wechatBill";
	}
	

	
	
	/**
	 * 新增页面，无需传值
	 */
	@Log("请求新增页面")
	@GetMapping("/add")
	@RequiresPermissions("brilliant:wechatBill:add")
	String add(){
	    return "brilliant/wechatBill/add";
	}
	
	@Log("请求编辑页面")
	@GetMapping("/edit/{billid}")
	@RequiresPermissions("brilliant:wechatBill:edit")
	String edit(@PathVariable("billid") String billid,Model model){
		WechatBillDO wechatBill = wechatBillService.get(billid);
		model.addAttribute("wechatBill", wechatBill);
	    return "brilliant/wechatBill/edit";
	}
	/**
	 * 新增页面
	 */
	@Log("请求新增页面带参数 ")
	@GetMapping("/addModel")
	@RequiresPermissions("brilliant:wechatBill:addModel")
	String addModel(){
		return "brilliant/wechatBill/addModel";
	}

	/**
	 * 编辑页面
	 */
	@Log("请求编辑页面带参数 ")
	@GetMapping("/editModel")
	@RequiresPermissions("brilliant:wechatBill:editModel")
	String editModel(){
		return "brilliant/wechatBill/editModel";
	}

	/**
         * 列表页面
         */
	@Log("请求列表页面 ")
	@GetMapping("/listPager")
	@RequiresPermissions("brilliant:wechatBill:listPager")
	String listPager(){
		return "brilliant/wechatBill/listPager";
	}

	//endregion

	//region 获取数据
	@Log("请求访问主页")
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("brilliant:wechatBill:wechatBill")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<WechatBillDO> wechatBillList = wechatBillService.list(query);
		int total = wechatBillService.count(query);
		PageUtils pageUtils = new PageUtils(wechatBillList, total);
		return pageUtils;
	}

	/**
	 * LayUi 分页查询
	 */
	@Log("请求LayUi页面 ")
	@ResponseBody
	@GetMapping("/PageLayUi_List_By_Query")
	@RequiresPermissions("brilliant:wechatBill:PageLayUi_List_By_Query")
	public PageLayUi<WechatBillDO> PageLayUi_List_By_Query(WechatBillDO query){

		List<WechatBillDO> dataList = wechatBillService.PageLayUi_List_By_Query(query);
		int total = wechatBillService.total(query);
		PageLayUi<WechatBillDO> pageLayUi= new PageLayUi<WechatBillDO>(0,"",total,dataList);
		return pageLayUi;
	}

	/**
	 * 根据query ，查询并返回一条记录
	 */
	@Log("请求查询页面，传参 ")
	@ResponseBody
	@GetMapping("/Get_Model_By_Query")
	@RequiresPermissions("brilliant:wechatBill:Get_Model_By_Query")
	public WechatBillDO Get_Model_By_Query(WechatBillDO query){
			WechatBillDO model = wechatBillService.Get_Model_By_Query(query);
		return model;
	}

	//endregion

	//region 提交数据
	/**
	 * 保存
	 */
	@Log("新增保存操作")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("brilliant:wechatBill:add")
	public R save( WechatBillDO wechatBill){
		if(wechatBillService.save(wechatBill)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@Log("修改保存操作")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("brilliant:wechatBill:edit")
	public R update( WechatBillDO wechatBill){
		wechatBillService.update(wechatBill);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@Log("列表删除页面数据")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("brilliant:wechatBill:remove")
	public R remove( String billid){
		if(wechatBillService.remove(billid)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@Log("按钮删除页面数据")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("brilliant:wechatBill:batchRemove")
	public R remove(@RequestParam("ids[]") String[] billids){
		wechatBillService.batchRemove(billids);
		return R.ok();
	}


	//endregion
	

	
}
